// ============================================================================
//
// Copyright (C) 2006-2007 Dengues
//
// Google Group: http://groups.google.com/group/dengues
// QQ Group: 24885404
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// ============================================================================
package org.dengues.core.editor;

import java.util.List;

import org.dengues.core.CorePlugin;
import org.dengues.core.components.IComponentsFactory;
import org.dengues.core.components.IXMLComponent;
import org.dengues.core.editor.utils.GEFEditorUtils;
import org.dengues.core.resource.WarehouseResourceFactory;
import org.dengues.core.warehouse.ENodeCategoryName;
import org.dengues.core.warehouse.IWarehouseNode;
import org.eclipse.core.runtime.IPath;
import org.eclipse.ui.part.FileEditorInput;

/**
 * qzhang class global comment. Detailled comment <br/>
 */
public abstract class AbstractEditorInput extends FileEditorInput {

    protected IWarehouseNode warehouseNode;

    protected IWarehouseNode parentNode;

    private final IComponentsFactory factory = CorePlugin.getDefault().getDesignerCoreService().getComponentsFactory();;

    private final IPath path;

    private String editorUniqueName;

    /**
     * qzhang ProcessEditorInput constructor comment.
     * 
     * @param processType
     */
    public AbstractEditorInput(String objName, ENodeCategoryName name, IPath path) {
        super(WarehouseResourceFactory.getFileFromEMF(objName, name, path));
        this.path = path;
        this.editorUniqueName = GEFEditorUtils.getEditorUniqueName(objName, name);
    }

    /**
     * Getter for warehouseNode.
     * 
     * @return the warehouseNode
     */
    public IWarehouseNode getWarehouseNode() {
        return this.warehouseNode;
    }

    public void setParentNode(IWarehouseNode parentNode) {
        this.parentNode = parentNode;
    }

    protected IXMLComponent getComponent(String compName) {
        List<IXMLComponent> components = factory.getComponents();
        for (IXMLComponent component : components) {
            if (component.getName().equals(compName)) {
                return component;
            }
        }
        return null;
    }

    @Override
    public IPath getPath() {
        return this.path;
    }

    /**
     * Getter for editorUniqueName.
     * 
     * @return the editorUniqueName
     */
    public String getEditorUniqueName() {
        return this.editorUniqueName;
    }

}
